﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using System.Data;
using System.Web.SessionState;

namespace UI.Secretaria
{
    public partial class frmImprimeNomina : System.Web.UI.Page
    {
        public static Int32 x =0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               
                if (x == 0)
                {
                    ImprimeNomina();
                }
               
            }
            


            
        }
        void ImprimeNomina()
        {

            //var reporte = new ReportDocument();
            //reporte.Load(Server.MapPath("Reportes/Proveedores.rpt"));
            //reporte.SetDataSource(ds.Tables[0]);
            //reporte.DataSourceConnections[0].SetConnection("NABUCODONOSOR", "AdventureWorks", "usuario", "********");

            //crpReporte.ReportSource = reporte;

            /*se exporta a excel*/

            try
            {
                DataSet dsNomina = new DataSet();
                DataTable Detalle = (DataTable)Session["DetalleNomina"];
                DataTable dato = (DataTable)Session["DatoNomina"];
                dato.TableName = "Cabecera";
                Detalle.TableName = "Detalle";

                dsNomina.Tables.Add(dato);
                dsNomina.Tables.Add(Detalle);

                String mapa = Server.MapPath("nomina.rpt");

                var reporte = new ReportDocument();
                reporte.Load(mapa);
                reporte.SetDataSource(dsNomina);
                crpReporte.ReportSource = reporte;
                dsNomina.Dispose();
                reporte.Close();
            }

            catch (Exception ex)
            {
                Label1.Text = ex.Message;
            }
            //rptreporte.ResourceName = "nomina.rpt";

            //rptreporte.SetDataSource(dsNomina);
            //rptreporte.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, true, "Nomina");

        }

    }
}